package br.usp.ime.macmovel.android;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

/**
 * This class manages the tabs containing all the activities of the app.
 */
public class MainActivity extends TabActivity
{
    /**
     * Creates a tab for each activity in the app. 
     * The leftmost tab (library) is selected by default.
     */
	public void onCreate(Bundle savedInstanceState) 
	{
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.main);
	    
	    Resources res = getResources(); // Resource object to get Drawables
	    TabHost tabHost = getTabHost();  // The activity TabHost
	    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
	    Intent intent;  // Reusable Intent for each tab

	    // Create an Intent to launch an Activity for the tab (to be reused)
	    intent = new Intent().setClass(this, LibraryActivity.class);
	    
	    //Initialize a TabSpec for each tab and add it to the TabHost
	    spec = tabHost.newTabSpec("library").setIndicator(getString(R.string.library),
	                      res.getDrawable(R.drawable.ic_tab_library))
	                  .setContent(intent);
	    tabHost.addTab(spec);
	    
	    //Do the same for the other tabs
	    intent = new Intent().setClass(this, LibraryMapActivity.class);
	    spec = tabHost.newTabSpec("library_map").setIndicator(getString(R.string.library_map),
	                      res.getDrawable(R.drawable.ic_tab_library_dir))
	                  .setContent(intent);
	    tabHost.addTab(spec);
	    
	    intent = new Intent().setClass(this, BandexActivity.class);
	    spec = tabHost.newTabSpec("bandex").setIndicator(getString(R.string.bandex),
                res.getDrawable(R.drawable.ic_tab_bandex))
            .setContent(intent);
	    tabHost.addTab(spec);

	    intent = new Intent().setClass(this, UspMapActivity.class);
	    spec = tabHost.newTabSpec("maps").setIndicator(getString(R.string.maps),
                res.getDrawable(R.drawable.ic_tab_map))
            .setContent(intent);
	    tabHost.addTab(spec);



	    tabHost.setCurrentTab(0);
	}
}
